@extends('teacher.base')
@section('main')
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
     <legend>问题管理</legend>
    </fieldset>
    @include('teacher.error')
    <form class="layui-form"  method="post" action="" enctype="multipart/form-data">
    {!! csrf_field() !!}
	  <div class="layui-form-item">
    <label class="layui-form-label">题目</label>
    <div class="layui-input-block">
      <input type="text" name="title" lay-verify="required" placeholder="请输入题目名字" class="layui-input">
    </div>
  	</div>

    <div class="layui-form-item">
    <label class="layui-form-label">年级</label>
    <div class="layui-input-block">
      <select name="grade" lay-filter="aihao">
        @foreach($grades as $v)
        <option value="{{ $v->id }}">{{ $v->name }}</option>
        @endforeach
      </select>
    </div>
    </div>

	<div class="layui-form-item">
    <label class="layui-form-label">科目</label>
    <div class="layui-input-block">
      <select name="subject" lay-filter="aihao">
        @foreach($subjects as $v)
        <option value="{{ $v->id }}">{{ $v->name }}</option>
        @endforeach
      </select>
    </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">题目类型</label>
      <div class="layui-input-block" id="mychose">
        <input type="radio" id="chose" lay-filter="filter" name="is_type" value="1" title="选择题" checked="">
        <input type="radio" id="chose" lay-filter="filter" name="is_type" value="3" title="选择题(图片)" >
        <input type="radio" id="fill" lay-filter="filter" name="is_type" value="2" title="填空题">
      </div>
    </div>
	

	<div id="chose_html">

  </div>
  <div id="answer">

  </div>


  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
    </form>

<script>
//console.log($('input[name="chose"]'));
var chose_html = `
  <div class="layui-form-item">
    <label class="layui-form-label">A、</label>
    <div class="layui-input-inline">
      <input type="text" name="answer[]" lay-verify="required" placeholder="请输入选项" class="layui-input">
    </div>
  <label class="layui-form-label">解析：</label>
  <div class="layui-input-inline">
      <input type="text" name="content[]" placeholder="可不填" class="layui-input">
    </div>
  
    </div>
  <div class="layui-form-item">
    <label class="layui-form-label">B、</label>
    <div class="layui-input-inline">
      <input type="text" name="answer[]" lay-verify="required" placeholder="请输入选项" class="layui-input">
    </div>
  <label class="layui-form-label">解析：</label>
  <div class="layui-input-inline">
      <input type="text" name="content[]" placeholder="可不填" class="layui-input">
    </div>
  
    </div>
  <div class="layui-form-item">
    <label class="layui-form-label">C、</label>
    <div class="layui-input-inline">
      <input type="text" name="answer[]" lay-verify="required" placeholder="请输入选项" class="layui-input">
    </div>
  <label class="layui-form-label">解析：</label>
  <div class="layui-input-inline">
      <input type="text" name="content[]" placeholder="可不填" class="layui-input">
    </div>
  
    </div>
  <div class="layui-form-item">
    <label class="layui-form-label">D、</label>
    <div class="layui-input-inline">
      <input type="text" name="answer[]" lay-verify="required" placeholder="请输入选项" class="layui-input">
    </div>
  <label class="layui-form-label">解析：</label>
  <div class="layui-input-inline">
      <input type="text" name="content[]" placeholder="可不填" class="layui-input">
    </div>
  
    </div>
 `;

 var chose_html2 = `
  <div class="layui-form-item">
  <label class="layui-form-label">答案（多个 , 逗号隔开）</label>
  <div class="layui-input-block">
    <input type="text" name="answers" required  lay-verify="required" placeholder="请输入答案" autocomplete="off" class="layui-input">
  </div>

<div class="layui-form-item layui-form-text">
  <label class="layui-form-label">解析：</label>
  <div class="layui-input-block">
    <textarea name="desc" name="content" placeholder="请输入内容" class="layui-textarea"></textarea>
  </div>
</div>
</div>
 `;

 var chose_html3 = `
  <div class="layui-form-item">
    <label class="layui-form-label">A、</label>
    <div class="layui-input-inline">
      <input type="file" name="answer[]" lay-verify="required" placeholder="请输入选项" class="layui-input">
    </div>
  <label class="layui-form-label">解析：</label>
  <div class="layui-input-inline">
      <input type="text" name="content[]" placeholder="可不填" class="layui-input">
    </div>
  
    </div>
  <div class="layui-form-item">
    <label class="layui-form-label">B、</label>
    <div class="layui-input-inline">
      <input type="file" name="answer[]" lay-verify="required" placeholder="请输入选项" class="layui-input">
    </div>
  <label class="layui-form-label">解析：</label>
  <div class="layui-input-inline">
      <input type="text" name="content[]" placeholder="可不填" class="layui-input">
    </div>
  
    </div>
  <div class="layui-form-item">
    <label class="layui-form-label">C、</label>
    <div class="layui-input-inline">
      <input type="file" name="answer[]" lay-verify="required" placeholder="请输入选项" class="layui-input">
    </div>
  <label class="layui-form-label">解析：</label>
  <div class="layui-input-inline">
      <input type="text" name="content[]" placeholder="可不填" class="layui-input">
    </div>
  <div class="layui-word-aux"><input type="checkbox" name="is_success[]" title="正确答案" value="3" ></div>
    </div>
  <div class="layui-form-item">
    <label class="layui-form-label">D、</label>
    <div class="layui-input-inline">
      <input type="file" name="answer[]" lay-verify="required" placeholder="请输入选项" class="layui-input">
    </div>
  <label class="layui-form-label">解析：</label>
  <div class="layui-input-inline">
      <input type="text" name="content[]" placeholder="可不填" class="layui-input">
    </div>
  
    </div>
 `;

 answer = `
 <div class="layui-form-item">
    <label class="layui-form-label">正确答案</label>
    <div class="layui-input-block">
    <input type="checkbox" name="is_success[0]" title="【A】正确" value="1">
    <input type="checkbox" name="is_success[1]" title="【B】正确" value="1">
    <input type="checkbox" name="is_success[2]" title="【C】正确" value="1">
    <input type="checkbox" name="is_success[3]" title="【D】正确" value="1">
    </div>
  </div>

 `;
 $(document).ready(function() {

  $('#chose_html').html(chose_html);
  $('#answer').html(answer);

});

layui.use(['form', 'layer','element'], function(){
  var form = layui.form
  ,$ = layui.jquery
  ,element = layui.element
  ,layer = layui.layer;
	
form.on('radio(filter)', function(data){
  if(data.value==1){
	$('#chose_html').html(chose_html);
  $('#answer').show();
  }else if(data.value==2){
	$('#chose_html').html(chose_html2);
  $('#answer').hide();

  }else if(data.value==3){
  $('#chose_html').html(chose_html3);
  $('#answer').show();

  }
  console.log(data.elem); //得到radio原始DOM对象
  console.log(data.value); //被点击的radio的value值
});  


});
</script>

@endsection
